package cn.edu.nuc.fourth.services.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.edu.nuc.fourth.dao.MajorMapper;
import cn.edu.nuc.fourth.dao.ProjectMapper;
import cn.edu.nuc.fourth.dao.SchoolMapper;
import cn.edu.nuc.fourth.model.CheckSchool;
import cn.edu.nuc.fourth.model.Major;
import cn.edu.nuc.fourth.model.Project;
import cn.edu.nuc.fourth.model.School;
import cn.edu.nuc.fourth.services.interfaces.CheckService;

@Service
public class CheckServiceImpl implements CheckService {

	/**
	 * 学校基本条件审核
	 */
	@Autowired
	private SchoolMapper smapper;

	@Autowired
	private MajorMapper mmapper;
	@Autowired
	private ProjectMapper pmapper;

	@Override
	public CheckSchool checkSchool(Integer userid, String date) {

		CheckSchool cs = new CheckSchool();
		School school = smapper.oneSchool(String.valueOf(userid), date);
		Major major = mmapper.noadd(String.valueOf(userid), date);
		cs.setSchool(school);
		cs.setMajor(major);
		return cs;
	}

	/**
	 * 执行审核
	 */
	@Override
	public CheckSchool dochekcSchool(Major major, School school, String userid) {

		smapper.updateByPrimaryKeySelective(school);
		mmapper.updateByPrimaryKeySelective(major);
		CheckSchool cs = new CheckSchool();
		School s = smapper.oneSchool(String.valueOf(userid), school.getSdate());
		Major m = mmapper.noadd(String.valueOf(userid), major.getMdate());
		cs.setSchool(s);
		cs.setMajor(m);

		return cs;
	}

	@Override
	public List<Project> checkProject(String userid, String date) {

		List<Project> list = pmapper.findBydate(userid, date);
		return list;
	}

	@Override
	public List<Project> docheckProject(Project project) {

		pmapper.updateByPrimaryKeySelective(project);
		List<Project> list = pmapper.findBydate(String.valueOf(project.getUserid()), project.getDate());
		return list;
	}

}
